#!/usr/bin/env python
#coding=utf-8
#########################################################################
# File Name: simpledownload.py
# Author: Wulei
# mail: wlinpisces@gmail.com
# Created Time: Tue 25 Feb 2014 10:28:44 PM
#########################################################################
import tornado.web
import tornado.ioloop
from tornado.options import define,options,parse_command_line
import os

files = os.listdir('./files')

class DownHandler(tornado.web.RequestHandler):
    def get(self,filename):
        self.render('index.html',files = files)
        self.set_header('Content-Type','application/octet-stream')
        f = open('files/'+filename,'rb')
        return f.read()

class defaultHandler(tornado.web.RequestHandler):
    def get(self):
        self.write('hello,world')


if __name__ == '__main__':
    app = tornado.web.Application([
        ('/download', DownHandler),
        ('/',defaultHandler),
    ])

    app.listen(3000)
    tornado.ioloop.IOLoop.instance().start()
